<template>
  <div>
    <el-table>
      :data="tableData"  <!--v-bind进行缩写简写-->
    border
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="phone"
      label="电话"
      width="180">
    </el-table-column>
    <el-table-column
      prop="email"
      label="邮箱"
      width="180">
    </el-table-column>
    <el-table-column
      prop="createTime"
      label="创建时间"
      width="180">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址" >
    </el-table-column>
    </el-table>
    <el-pagination
      :page-size="pageSize"
      :pager-count="currentPage"
      layout="prev, pager, next"
      align="right"
      :total="totals"
      @current-change="gotopage">

    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      /*返回四个值  不知道哪个数值可以取user.js去找*/
      pageSize:5,//每页的条数
      currentPage:1,//当前页
      totals:0,//条数是几条
      tableData:[]//表格返回的数据
    }
  },
  methods:{//这个写多个方法，后面我们要抽取公共的方法
    gotopage(curr){//写一个gotopage的方法并且填写为curr
      this.currentPage=curr;  //this指代当前的对象,代表我们要拿取到这个值
      this.page()//调用共用的方法
    },
    page() {
      //1.先写axious
      //2.写mock  获取模拟接口
      this.$http.post("/user/list",{"currentPage":this.currentPage,"pageSize":this.pageSize})
      .then(result=>{//填写指向函数
        this.tableData=result.data.rows
        this.totals=result.data.totals
      })
      .catch(result=>{
        alert("报错")
      })
    }
  },
  mounted() {
    this.page()
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
